<template>
	<view class="wallet">
		<view class="wallet_card flex_c">
			<view class="blance flex_c">
				<view>{{Math.floor(balance)}}</view>
				<text>我的余额(曝光量)</text>
			</view>
			<view class="list_btn flex_center">
				<view @click="$util.toUrl('/pages/store/generalization/rechargeList')">充值记录</view>
				<view @click="$util.toUrl('/pages/store/generalization/consumptionList')">消费记录</view>
			</view>
		</view>


		<view class="config">
			<u-grid :border="false">
				<u-grid-item v-for="(item,index) in config" :key="index" @click="onChooseConfig(item)">
					<view class="config_item" :id="config_id == item.id ? 'select' : ''">
						<view class="top">
							<text class="title">充值曝光量</text>
							<text class="num">{{item.name}}</text>
						</view>

						<view class="line"></view>

						<view class="bottom">
							<text class="price">{{item.price.split('.')[0]}}元</text>
						</view>
					</view>
				</u-grid-item>
			</u-grid>
		</view>

		<view class="pay_type">
			<text class="title">支付方式</text>
			<view class="type_item flex_r_between" @click="pay_type = 1">
				<view class="type_title flex_center">
					<image src="/static/public/wechat.png"></image>
					<text>微信支付</text>
				</view>
				<image :src="`/static/public/select${pay_type == 1 ? '_s' : ''}.png`" class="type_select"></image>
			</view>
			<view class="type_item flex_r_between" @click="pay_type = 2">
				<view class="type_title flex_center">
					<image src="/static/public/alipay.png"></image>
					<text>支付宝支付</text>
				</view>
				<image :src="`/static/public/select${pay_type == 2 ? '_s' : ''}.png`" class="type_select"></image>
			</view>
		</view>


		<view class="btn_box flex_r_between">
			<view class="left flex_center">
				需要支付:
				<text class="flex_center"><i>￥</i>{{price}}</text>
			</view>
			<view class="btn" @click="toPay">立即支付</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				config: [],

				config_id: 0,

				pay_type: 1,

				balance: '0.00',

				price: '0',
			}
		},
		methods: {
			getConfig() {
				this.$get('/popularize/getPopularizeConfig').then(res => {
					res.data.list.forEach(element => {
						if (element.id == 6) {
							this.config = element.child;
							this.config_id = this.config[0].id;
							this.price = Math.floor(this.config[0].price);
						}
					})
				})
			},

			onChooseConfig(item) {
				this.config_id = item.id;
				this.price = Math.floor(item.price);
			},

			getBalance() {
				this.$get('/popularize/getBalance').then(res => {
					this.balance = res.data.balance;
				})
			},

			// 创建订单
			toPay() {
				this.$post('/popularize/payPopularizeBalance', {
					pay_type: this.pay_type,
					config_id: this.config_id
				}).then(res => {
					this.$util.msg(`订单id:${res.data.order_id}----${res.msg}`)
				})
			},


		},

		created() {
			this.getConfig();
			this.getBalance();
		},
	}
</script>

<style lang="less" scoped>
	.wallet {}

	.wallet_card {
		height: 266rpx;
		background: url('https://qiniu-cdn.maeiyun.com//h5static/store/gen_wallet_bg.png') 0 0 no-repeat;
		background-size: 100%;
		padding-top: 36rpx;
		margin: 16rpx 0;

		.blance {
			flex: 1;

			view {
				font-weight: 600;
				font-size: 64rpx;
				color: #131313;
			}

			text {
				font-size: 24rpx;
				color: #999999;
			}
		}

		.list_btn {
			border-top: 2rpx solid #F4F4F4;
			height: 78rpx;
			width: 100%;

			view {
				text-align: center;
				flex: 1;
				font-size: 28rpx;
				color: #333333;
			}
		}

	}

	.config {
		.config_item {
			width: 224rpx;
			height: 232rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			border: 2rpx solid transparent;
			margin-bottom: 16rpx;
			padding: 20rpx 0 0 12rpx;

			.top {
				.title {
					font-size: 28rpx;
					color: #999999;
				}

				.num {
					font-weight: 600;
					font-size: 34rpx;
					color: #131313;
				}
			}

			.line {
				width: 168rpx;
				height: 2rpx;
				background: #EEEEEE;
				margin: 16rpx 0;
			}

			.bottom {
				font-weight: 600;
				font-size: 32rpx;
				color: #FD2A53;
			}
		}

		#select {
			width: 224rpx;
			height: 232rpx;
			background: #FFEFF2;
			border-radius: 16rpx;
			border: 2rpx solid #FFDCE3;

			.top {
				.title {
					color: #FD2A53;
				}
			}

			.line {
				background: #FFDCE3;
			}

		}
	}

	.pay_type {
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 32rpx;
		margin-bottom: 30rpx;

		.title {
			font-size: 28rpx;
			color: #131313;
		}

		.type_item {
			margin-top: 40rpx;

			.type_title {
				image {
					width: 48rpx;
					height: 48rpx;
					background: #48B338;
					border-radius: 8rpx;
					margin-right: 16rpx;
				}

				text {
					font-size: 28rpx;
					color: #131313;
				}
			}

			.type_select {
				width: 40rpx;
				height: 40rpx;
			}
		}

	}

	.btn_box {
		position: fixed;
		background: #FFFFFF;
		box-shadow: 0rpx -2rpx 16rpx 0rpx rgba(0, 0, 0, 0.05);
		bottom: 0;
		left: 0;
		width: 100vw;
		padding: 14rpx 32rpx 60rpx;

		.left {
			font-weight: 500;
			font-size: 28rpx;
			color: #131313;

			text {
				font-weight: 600;
				font-size: 40rpx;
				color: #FD2A53;

				i {
					font-size: 28rpx;
					font-style: normal;
				}
			}
		}

		.btn {
			width: 200rpx;
			height: 72rpx;
			background: #FD2A53;
			border-radius: 40rpx;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
			line-height: 72rpx;
			text-align: center;
		}
	}
</style>